var express = require('express');
var router = express.Router();
const menuService = require('../service/userMenusService')

router.get('/query', async function (req, res, next) {
    let { userId, menuId } = req.query
    let result = await menuService.query({ userId, menuId });
    res.json({
        code: 200,
        data: result
    })
});

router.post('/add', async function (req, res, next) {
    let { userId, menuId, name, price, picture, description } = req.body
    console.log("传递过来的数据",userId, menuId, name, price, picture, description);
    
    let result = await menuService.query({ userId, name });
    if (result.length > 0) {
        return res.json({
            code: 400,
            msg: '该菜单已存在'
        })
    }
    let result2 = await menuService.add({ userId, menuId, name, price, picture, description })
    res.json({
        code: 200,
        data: result2
    })
});

module.exports = router;